define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fa/comic/index' + location.search,
                    add_url: 'fa/comic/add',
                    edit_url: 'fa/comic/edit',
                    del_url: 'fa/comic/del',
                    multi_url: 'fa/comic/multi',
                    import_url: 'fa/comic/import',
                    table: 'fa_comic',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'navigate.title',
                            title: '导航标题',
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                        },
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {
                            field: 'thumb',
                            title: __('Thumb'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.images,
                            events: Table.api.events.image,
                        },
                        {
                            field: 'swiper',
                            title: __('Swiper'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.images,
                            events: Table.api.events.image,
                        },
                        {field: 'author', title: __('Author'), operate: 'LIKE'},
                        {field: 'tags', title: '标签', operate: 'LIKE', formatter: Table.api.formatter.flag,},
                        {
                            field: 'intro',
                            title: __('Intro'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'created_at',
                            title: __('Created_at'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false
                        },
                        {
                            field: 'updated_at',
                            title: __('Updated_at'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: ' chapter_list',
                                    title: '漫画章节',
                                    text: '漫画章节',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'fa/chapter/index?comic_id={ids}',
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
